package com.junt.webnovel;

import android.content.Context;
import android.util.Log;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;

/**
 * url过滤规则
 */
class AdFilterTool {

    private static final String TAG = "AdFilterTool";
    private static Set<String> filters = new HashSet<>();

    public static void init(Context context) {
        File file = new File(context.getFilesDir(), "filters.txt");
        try {
            BufferedReader reader = new BufferedReader(new FileReader(file));
            String line;
            while ((line = reader.readLine()) != null) {
                filters.add(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean isAd(String url) {
        if (filters.contains(url)) {
            return true;
        }
        return false;
    }
}
